import * as Router from 'koa-router';
import menuService from "./../service/_menuService";
let router = new Router();
router.prefix('/api')


/**
 * 添加菜单
 */
router.post('/menu/createMenu', async (ctx: any, next: any) => {
    let res = ctx.request.body;
    let result: any = await menuService.createMenu(res);
    ctx.status = 200;
    ctx.body = result;
    await next()
})

/**
 * 获取菜单列表
 */
router.get('/menu/queryList', async (ctx: any, next: any) => {
    let result: any = await menuService.queryList();
    ctx.status = 200;
    ctx.body = result;
    await next()
})

/**
 * 根据主键 修改 评分 
 */
router.post('/menu/updateMenuById', async (ctx: any, next: any) => {
    let res = ctx.request.body;
    let result: any = await menuService.updateMenuById(res);
    ctx.status = 200;
    ctx.body = result;
    await next()
})

/**
 * 测试
 */
router.get('/menu/test', async (ctx: any, next: any) => {
    let res = { _id: "5ab9cf1c9aa8272837a6e40f", star: '1', userId: '1' }
    let result: any = await menuService.updateMenuById(res);
    ctx.status = 200;
    ctx.body = result;
    await next()
})

/**
 * 获取openId
 */
router.post('/menu/queryOpenIdByCode', async (ctx: any, next: any) => {
    let res = ctx.request.body;
    let result: any = await menuService.queryOpenIdByCode(res);
    ctx.status = 200;
    ctx.body = result;
    await next()
})

/**
 * 测试专用  这个接口无实际意义 
 */
router.get('/menu/testUpdate', async (ctx: any, next: any) => {
    let res = ctx.request.body;
    let result: any = await menuService.testUpdate();
    ctx.status = 200;
    ctx.body = result;
    await next()
})


export default router;